package com.example.mpdata.biz;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mpdata.dao.PersonMapper;
import com.example.mpdata.po.Person;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;

@Service
@DS("db2")
public class PersonService extends ServiceImpl<PersonMapper, Person> {


    @Resource
    private PersonMapper personMapper;

    /**
     * 应使用
     * dynamic-datasource-spring-boot-starter
     * 自带的 事务注解 @DSTransactional
     *
     * https://dynamic-datasource.com/guide/faq/Failed-Switch-Database.html#_1-%E5%BC%80%E5%90%AF%E4%BA%86spring%E7%9A%84%E4%BA%8B%E5%8A%A1%E3%80%82
     * https://dynamic-datasource.com/guide/tx/Local.html#%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95
     */
    @DSTransactional
    public void delByIds(Long[] ids){
        personMapper.deleteBatchIds(Arrays.asList(ids));
    }

}
